<?php
namespace app\index\controller;
use think\Controller;

class Base extends Controller
{
    public function _initialize()
    {
    	$citys = model('City')->getCitysByParentId(['neq',0]);

    	$id = input('id','0','intval');
    	$currentCity = '';
    	$user = session('user','','index');
    	$categorys = model('Category')->getCategorysByParentId(['gt',-1]);
    	// var_dump($user);die;

        //优先级 用户选择城市 > session保存的城市 > 系统默认城市 > 自定义城市

    	if($id){
    		$currentCity = model('city')->where(['id' => $id])->find();
    	}
    	if(!$currentCity){
    		$currentCity = session('currentCity','','index');
    	}

    	if(!$currentCity){
    		$currentCity = model('city')->where(['is_default' => 1])->find();
    	}

    	if(!$currentCity){
    		$currentCity = model('city')->where(['id' => 2])->find();
    	}

    	session('currentCity',$currentCity,'index');

    	$this->assign('citys',$citys);
    	$this->assign('currentCity',$currentCity);
    	$this->assign('user',$user);
    	$this->assign('categorys',$categorys);
    	$this->assign('controller',strtolower(request()->controller()));
    	$this->assign('title','金猫团购网');
    }
}
